package com.easy.controller;

import com.easy.bean.Department;
import com.easy.service.DepartmentService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("department")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    // 分页查询（放在动态路径前）
    @GetMapping("page")
    public Result page(Page page, Department department) {
        Object obj = departmentService.page(page, department);
        return Result.success(obj);
    }

    // 新增科室
    @PostMapping
    public Result add(@RequestBody Department department) {
        Object obj = departmentService.add(department);
        return Result.success(obj);
    }

    // 编辑科室
    @PutMapping
    public Result edit(@RequestBody Department department) {
        Object obj = departmentService.edit(department);
        return Result.success(obj);
    }

    // 删除科室
    @DeleteMapping("{id}")
    public Result del(@PathVariable("id") Integer id) {
        Object obj = departmentService.del(id);
        return Result.success(obj);
    }

    // 根据ID查询科室
    @GetMapping("{id}")
    public Result one(@PathVariable("id") Integer id) {
        Object obj = departmentService.one(id);
        return Result.success(obj);
    }

    // 查询所有科室
    @GetMapping("all")
    public Result all(Department department) {
        Object obj = departmentService.all(department);
        return Result.success(obj);
    }
}
